#include <stdio.h>	/* printf */
#include "comm.h"

#define CLIENT_STRING1 "Client hello world!"
#define CLIENT_STRING2 "I'm client"
#define CLIENT_STRING3 "e(exit)"	/* 通知server退出 */

static char rbuf[MSG_QUEUE_MAXSIZE];

int main()
{
	int msgid = get_msg_queue();
	if (msgid < 0)
		return -1;

	printf("send start...\n");

	send_msg_queue(msgid, CLIENT_ID, CLIENT_STRING1, sizeof(CLIENT_STRING1));
	send_msg_queue(msgid, CLIENT_ID, CLIENT_STRING2, sizeof(CLIENT_STRING2));

	int len;
	for (int i = 0; i < 2; i++) {
		len = recv_msg_queue(msgid, SERVER_ID, rbuf);
		if (len > 0) {
			rbuf[len + 1] = '\0';
			printf("server-->client[%d]: %s\n", len, rbuf);
		}
	}

	send_msg_queue(msgid, CLIENT_ID, CLIENT_STRING3, sizeof(CLIENT_STRING3));

	/* 客户端不要关闭消息队列 */

	return 0;
}
